import intl from "react-intl-universal";

const langArr = [
  ["zh_CN", '简体中文'],
  ["en_US", 'English']
]

if (!localStorage.lang) {
  localStorage.lang = langArr[0][0]
}

const initialLang = localStorage.lang
const locales = {}

for (const i in langArr) {
  let item = langArr[i]
  locales[item[0]] = require(`./locals/${item[0]}`)
}

// intl.init({
//   currentLocale: initialLang,
//   locales
// })
//
// export default intl

export default () => new Promise(resolve => {
  intl
    .init({
      currentLocale: initialLang,
      locales
    })
    .then(() => {
      resolve(intl)
    })
})
